<?php
/**
 * 记账Model
 * @author solar
 */
class BillModel extends BaseModel 
{
	public static $name='bill';
	public static $primary='b_id';
	
	public function __construct() {
		parent::__construct(CoreFactory::db(),self::$name,self::$primary);
	}
	
	/**
	 * 创建账单记录
	 * @author solar
	 * @param int $g_id
	 * @param int $c_id
	 * @param int $amount
	 * @param int $note
	 * @return boolean
	 */
	public function createBill($g_id,$c_id,$amount,$note) {
		$row['g_id']=$g_id;
		$row['c_id']=$c_id;
		$row['b_amount']=$amount;
		$row['b_note']=$note;
		$row['b_creator']=CoreFactory::session()->get('user_id');
		$row['b_create_time']=time();
		return $this->insert($row);
	}
	
	/**
	 * 账单是否存在记账记录
	 * @author solar
	 * @param int $c_id
	 * @return boolean
	 */
	public function hasBill($c_id) {
		$row=$this->db->fetchRow('SELECT b_id FROM `bill` WHERE c_id='.$c_id.' LIMIT 1');
		return $row ? true : false;
	}
}

?>